package com.javaweb.bookstore;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.javaweb.bookstore.entity.Book;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class JacksonSerializationExample {

    public static void main(String[] args) throws Exception {

        String id = UUID.randomUUID().toString();

        ObjectMapper mapper = new ObjectMapper();

        // 创建对象实例
        Book b = new Book("张三", 25);
        List<Book> bs = new ArrayList<>();
        bs.add(b);

        // 序列化为JSON字符串
        String jsonString = mapper.writeValueAsString(bs);
        System.out.println("序列化结果: " + jsonString);


    }
}